package com.xsyz.review.aopanno;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author xsyz
 * @created 2020-12-27   16:22
 */
@Aspect
@Component
public class UserProxy {
    @Pointcut("execution(* com.xsyz.review.*.*.*(..))")
    public void aop() {

    }

    @Before(value = "aop()")
    public void before(JoinPoint joinPoint) {

        String name = joinPoint.getSignature().getName();
        System.out.println("before*******************" + name);
    }

    @After("aop()")
    public void after(JoinPoint joinPoint) {
        System.out.println("after*************" + joinPoint.getSignature().getName());
    }

    @Around("aop()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知之前");
        proceedingJoinPoint.proceed();
        System.out.println("环绕通知之后");

    }

    @AfterThrowing("aop()")
    public void throw1(JoinPoint joinPoint) {
        System.out.println("抛出异常*************" + joinPoint.getKind());
        System.out.println("getSignature:" + joinPoint.getSignature());
        System.out.println("getArg:" + joinPoint.getArgs().toString());
        System.out.println("getTarget:" + joinPoint.getTarget());
    }

}
